package org.gaaidou.ptarmigan.server.util;

import java.util.Arrays;

public class ByteArray {
    private byte[] data;

    private int currIndex;

    public ByteArray(int length) {
        data = new byte[length];
    }

    public byte[] compressAndGet() {
        return data = Arrays.copyOf(data, currIndex + 1);
    }



    public void add(byte v) {
        if (currIndex == data.length - 1) {
            grow();
        }
        data[currIndex] = v;
        currIndex++;
    }

    private void grow() {
        data = Arrays.copyOf(data, data.length * 2);
    }

}
